#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "define.h"
#include "save.h"


int crt_board[BOARD_ROW][BOARD_COL];
int crt_turn;
bool piece_selected;

void save_game(){
    FILE *file = fopen("save.dat", "wb");
    if(file == NULL){
        printf("Error: Could not open file\n");
        return;
    }
    for(int i = 0; i < BOARD_ROW; i++){
        for(int j = 0; j < BOARD_COL; j++){
            fprintf(file, "%d ", crt_board[i][j]);
        }
        fprintf(file, "\n");
    }
    fprintf(file, "%d\n", crt_turn);
    fclose(file);
}

void load_game(){
    FILE *file = fopen("save.dat", "rb");
    if(file == NULL){
        printf("Error: Could not open file\n");
        return;
    }
    for(int i = 0; i < BOARD_ROW; i++){
        for(int j = 0; j < BOARD_COL; j++){
            fscanf(file, "%d", &crt_board[i][j]);
        }
    }
    fscanf(file, "%d", &crt_turn);
    fclose(file);
}